package com.bdzl.admin.controller.data;

import java.util.List;
import java.util.Map;

import com.bdzl.admin.service.data.CountryService;
import com.bdzl.pub.controller.BaseController;
import com.bdzl.pub.entity.data.CountryDO;
import com.bdzl.pub.util.param.PageUtils;
import com.bdzl.pub.util.param.Query;
import com.bdzl.pub.util.param.R;
import org.springframework.stereotype.Controller;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * 国家表
 * 
 * @author yangyicai
 * @email yangyicai@foxmail.com
 * @date 2021-05-24 11:50:40
 */
 
@Controller
@RequestMapping("/bdzl/country")
public class CountryController extends BaseController {
	@Autowired
	private CountryService countryService;
	
	@GetMapping()
	String Country(){
	    return "bdzl/country/country";
	}
	
	@ResponseBody
	@GetMapping("/list")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<CountryDO> countryList = countryService.list(query);
		int total = countryService.count(query);
		PageUtils pageUtils = new PageUtils(countryList, total);
		return pageUtils;
	}
	
	@GetMapping("/add")
	String add(){
	    return "bdzl/country/add";
	}

	@GetMapping("/edit/{id}")
	String edit(@PathVariable("id") Integer id,Model model){
		CountryDO country = countryService.get(id);
		model.addAttribute("country", country);
	    return "bdzl/country/edit";
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	public R save(CountryDO country){
		if(countryService.save(country)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	public R update(@RequestBody @Validated CountryDO country){
		countryService.update(country);
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	public R remove( Integer id){
		if(countryService.remove(id)>0){
		return R.ok();
		}
		return R.error();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	public R remove(@RequestParam("ids[]") Integer[] ids){
		countryService.batchRemove(ids);
		return R.ok();
	}
	
}
